package com.teach.util;

import java.security.MessageDigest;
import java.util.Base64;

public class MD5 {

  private  MD5(){}

  public static String encode(String str) {
    try {
      MessageDigest md5 = MessageDigest.getInstance("MD5");
      byte[] digest = md5.digest(str.getBytes("utf-8"));
      return Base64.getEncoder().encodeToString(digest);
    }catch (Exception ex){
      throw new RuntimeException("md5加密失败",ex);
    }
  }
}
